home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sources / xroach / patch1.z / patch1
Text File  |  1994-09-27  |  15KB  |  539 lines

  1. Path: uunet!ukma!rex!samsung!cs.utexas.edu!sun-barr!newstop!exodus!prodnet.la.locus.com
  2. From: jta@prodnet.la.locus.com (JT Anderson)
  3. Newsgroups: comp.sources.x
  4. Subject: v12i052: xroach, Patch1, Part01/01
  5. Message-ID: <11188@exodus.Eng.Sun.COM>
  6. Date: 6 Apr 91 01:47:06 GMT
  7. References: <csx-12i052:xroach@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 527
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: JT Anderson <jta@prodnet.la.locus.com>
  13. Posting-number: Volume 12, Issue 52
  14. Archive-name: xroach/patch1
  15. Patch-To: xroach: Volume 12, Issue 51
  16.  
  17. -------
  18. Patch-To: xroach: Volume 12, Issue 51
  19. # This is a shar archive.  Extract with sh, not csh.
  20. # The rest of this file will extract:
  21. # README squish.xbm xroach.patch1
  22. # ----------------< cut here >---------------------- 
  23. echo extracting - README
  24. sed 's/^X//' > README << '~FUNKY STUFF~'
  25. XThis patch to xroach adds two new options and support for virtual root
  26. Xwindow managers, such as tvtwm.  It also fixes a couple of potential 
  27. Xmemory faults.
  28. X
  29. XThe new options are -squish to enable squishing roaches with the mouse
  30. Xand -rgc to set the color of the roach guts that splash out.  Yellowgreen
  31. Xis recommended.
  32. X
  33. XTo apply the patches, unpack this file in your xroach directory using sh
  34. Xthen incant:
  35. X
  36. X    patch -p0 <xroach.patch1
  37. ~FUNKY STUFF~
  38. echo extracting - squish.xbm
  39. sed 's/^X//' > squish.xbm << '~FUNKY STUFF~'
  40. X#define squish_width 48
  41. X#define squish_height 48
  42. X#define squish_x_hot -1
  43. X#define squish_y_hot -1
  44. Xstatic char squish_bits[] = {
  45. X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  46. X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. X   0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x20, 0x00,
  48. X   0x00, 0x00, 0x18, 0x08, 0x02, 0x00, 0x00, 0x40, 0x41, 0x52, 0x28, 0x00,
  49. X   0x00, 0x80, 0x81, 0x1c, 0x13, 0x00, 0x00, 0x00, 0x12, 0x69, 0x00, 0x00,
  50. X   0x00, 0x30, 0x88, 0x40, 0x09, 0x00, 0x00, 0x40, 0x40, 0x00, 0x04, 0x00,
  51. X   0x00, 0x90, 0x06, 0x01, 0x30, 0x00, 0x00, 0x98, 0x80, 0x02, 0x10, 0x00,
  52. X   0x80, 0x20, 0x00, 0x80, 0x44, 0x00, 0x00, 0x0c, 0x82, 0xb0, 0x00, 0x00,
  53. X   0x80, 0x22, 0x20, 0x10, 0x44, 0x00, 0x00, 0x04, 0x1e, 0xa1, 0x00, 0x00,
  54. X   0x00, 0x04, 0x02, 0xa6, 0x18, 0x06, 0x00, 0x80, 0x00, 0x80, 0x8b, 0x00,
  55. X   0x00, 0x88, 0x0e, 0x02, 0x01, 0x00, 0x40, 0x04, 0x05, 0x62, 0x50, 0x04,
  56. X   0x40, 0x00, 0x01, 0x50, 0x09, 0x00, 0x00, 0x28, 0x12, 0x13, 0x88, 0x04,
  57. X   0x40, 0xc1, 0x30, 0x40, 0x02, 0x00, 0x60, 0x02, 0x03, 0x50, 0xc1, 0x01,
  58. X   0x00, 0x42, 0x16, 0x94, 0x80, 0x06, 0x00, 0x00, 0x40, 0x10, 0x40, 0x00,
  59. X   0x00, 0x94, 0x10, 0xe4, 0x34, 0x02, 0x00, 0x80, 0x1c, 0x84, 0x89, 0x00,
  60. X   0x00, 0x11, 0x00, 0x00, 0x20, 0x02, 0x00, 0x30, 0x10, 0x80, 0x54, 0x00,
  61. X   0x00, 0x20, 0x91, 0xa5, 0xc4, 0x00, 0x00, 0x22, 0x20, 0x28, 0x92, 0x00,
  62. X   0x00, 0x52, 0x08, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x90, 0x02, 0x2c, 0x00,
  63. X   0x00, 0x10, 0x01, 0x49, 0x00, 0x00, 0x00, 0x40, 0x04, 0x12, 0x0e, 0x00,
  64. X   0x00, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x05, 0x40, 0x01, 0x00,
  65. X   0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  67. X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  68. X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  69. ~FUNKY STUFF~
  70. echo extracting - xroach.patch1
  71. sed 's/^X//' > xroach.patch1 << '~FUNKY STUFF~'
  72. X*** patchlevel.h    Tue Apr 02 11:59:19 1991
  73. X--- ../xroach/patchlevel.h    Tue Apr 02 11:57:25 1991
  74. X***************
  75. X*** 1 ****
  76. X! #define PATCHLEVEL 0
  77. X--- 1,4 ----
  78. X! 
  79. X! /* @(#)patchlevel.h    1.2 4/2/91 11:57:18 */
  80. X! 
  81. X! #define PATCHLEVEL 1
  82. X*** roachmap.h    Tue Apr 02 11:59:19 1991
  83. X--- ../xroach/roachmap.h    Tue Apr 02 11:55:42 1991
  84. X***************
  85. X*** 1,3 ****
  86. X--- 1,6 ----
  87. X+ 
  88. X+ /* @(#)roachmap.h    1.3 4/2/91 11:55:35 */
  89. X+ 
  90. X  #include "roach000.xbm"
  91. X  #include "roach015.xbm"
  92. X  #include "roach030.xbm"
  93. X***************
  94. X*** 22,27 ****
  95. X--- 25,32 ----
  96. X  #include "roach315.xbm"
  97. X  #include "roach330.xbm"
  98. X  #include "roach345.xbm"
  99. X+ 
  100. X+ #include "squish.xbm"
  101. X  
  102. X  #define ROACH_HEADINGS    24    /* number of orientations */
  103. X  #define ROACH_ANGLE    15    /* angle between orientations */
  104. X*** xroach.c    Tue Apr 02 11:59:18 1991
  105. X--- ../xroach/xroach.c    Tue Apr 02 11:53:42 1991
  106. X***************
  107. X*** 12,21 ****
  108. X--- 12,31 ----
  109. X        cc -o xroach roach.c -lX11 [-lsocketorwhatever] [-lm] [-l...]
  110. X  
  111. X      Dedicated to Greg McFarlane.   (gregm@otc.otca.oz.au)
  112. X+     
  113. X+     Squish option contributed by Rick Petkiewizc (rick@locus.com)
  114. X+     
  115. X+     Virtual root code adapted from patch sent by Colin Rafferty who
  116. X+     borrowed it from Tom LaStrange.  Several other folks sent similar
  117. X+     fixes.
  118. X  */
  119. X+ 
  120. X+ /* @(#)xroach.c    1.5 4/2/91 11:53:31 */
  121. X+ 
  122. X  #include <X11/Xlib.h>
  123. X  #include <X11/Xutil.h>
  124. X  #include <X11/Xos.h>
  125. X+ #include <X11/Xatom.h>
  126. X  
  127. X  #include <stdio.h>
  128. X  #include <math.h>
  129. X***************
  130. X*** 49,54 ****
  131. X--- 59,65 ----
  132. X  unsigned int display_width, display_height;
  133. X  int center_x, center_y;
  134. X  GC gc;
  135. X+ GC gutsGC;
  136. X  char *display_name = NULL;
  137. X  Pixel black, white;
  138. X  
  139. X***************
  140. X*** 55,60 ****
  141. X--- 66,74 ----
  142. X  int done = 0;
  143. X  int eventBlock = 0;
  144. X  int errorVal = 0;
  145. X+ Bool squishRoach = False;
  146. X+ Pixmap squishMap;
  147. X+ Bool squishWinUp = False;
  148. X  
  149. X  typedef struct Roach {
  150. X      RoachMap *rp;
  151. X***************
  152. X*** 84,89 ****
  153. X--- 98,104 ----
  154. X  int CalcRootVisible();
  155. X  int MarkHiddenRoaches();
  156. X  Pixel AllocNamedColor();
  157. X+ Window FindRootWindow();
  158. X  
  159. X  void
  160. X  main(ac, av)
  161. X***************
  162. X*** 98,105 ****
  163. X--- 113,123 ----
  164. X      float angle;
  165. X      XEvent ev;
  166. X      char *roachColor = "black";
  167. X+     char *gutsColor = NULL;
  168. X      int nVis;
  169. X      int needCalc;
  170. X+     Window squishWin;
  171. X+     XSetWindowAttributes xswa;
  172. X      
  173. X      /*
  174. X         Process command line options.
  175. X***************
  176. X*** 118,123 ****
  177. X--- 136,147 ----
  178. X      else if (strcmp(arg, "-roaches") == 0) {
  179. X          maxRoaches = strtol(av[++ax], (char **)NULL, 0);
  180. X      }
  181. X+     else if (strcmp(arg, "-squish") == 0) {
  182. X+         squishRoach = True;
  183. X+     }
  184. X+     else if (strcmp(arg, "-rgc") == 0) {
  185. X+         gutsColor = av[++ax];
  186. X+     }
  187. X      else {
  188. X          Usage();
  189. X      }
  190. X***************
  191. X*** 142,148 ****
  192. X      }
  193. X  
  194. X      screen = DefaultScreen(display);
  195. X!     rootWin = RootWindow(display, screen);
  196. X      black = BlackPixel(display, screen);
  197. X      white = WhitePixel(display, screen);
  198. X  
  199. X--- 166,172 ----
  200. X      }
  201. X  
  202. X      screen = DefaultScreen(display);
  203. X!     rootWin = FindRootWindow();
  204. X      black = BlackPixel(display, screen);
  205. X      white = WhitePixel(display, screen);
  206. X  
  207. X***************
  208. X*** 164,179 ****
  209. X--- 188,229 ----
  210. X      rp->cosine = cos(angle);
  211. X      }
  212. X  
  213. X+     /*
  214. X+       Create the squished pixmap
  215. X+     */
  216. X+     if (squishRoach) {
  217. X+         squishMap = XCreateBitmapFromData(display, rootWin,
  218. X+         squish_bits, squish_width, squish_height);
  219. X+     }
  220. X+ 
  221. X      roaches = (Roach *)malloc(sizeof(Roach) * maxRoaches);
  222. X  
  223. X      gc = XCreateGC(display, rootWin, 0L, &xgcv);
  224. X      XSetForeground(display, gc, AllocNamedColor(roachColor, black));
  225. X      XSetFillStyle(display, gc, FillStippled);
  226. X+ 
  227. X+     if (squishRoach && gutsColor != NULL) {
  228. X+         gutsGC = XCreateGC(display, rootWin, 0L, &xgcv);
  229. X+         XSetForeground(display, gutsGC, AllocNamedColor(gutsColor, black));
  230. X+         XSetFillStyle(display, gutsGC, FillStippled);
  231. X+     }
  232. X+     else
  233. X+     gutsGC = gc;
  234. X      
  235. X      while (curRoaches < maxRoaches)
  236. X      AddRoach();
  237. X      
  238. X      XSelectInput(display, rootWin, ExposureMask | SubstructureNotifyMask);
  239. X+ 
  240. X+     if (squishRoach) {
  241. X+     xswa.event_mask = ButtonPressMask;
  242. X+     xswa.override_redirect = True;
  243. X+     squishWin = XCreateWindow(display, rootWin, 0, 0,
  244. X+             display_width, display_height, 0,
  245. X+             CopyFromParent, InputOnly, CopyFromParent,
  246. X+             CWOverrideRedirect | CWEventMask, &xswa);
  247. X+     XLowerWindow(display, squishWin);
  248. X+     }
  249. X      
  250. X      needCalc = 1;
  251. X      while (!done) {
  252. X***************
  253. X*** 184,195 ****
  254. X          if (needCalc) {
  255. X          needCalc = CalcRootVisible();
  256. X          }
  257. X!         nVis = MarkHiddenRoaches();
  258. X          if (nVis) {
  259. X          ev.type = SCAMPER_EVENT;
  260. X          }
  261. X          else {
  262. X!         DrawRoaches();
  263. X          eventBlock = 1;
  264. X          XNextEvent(display, &ev);
  265. X          eventBlock = 0;
  266. X--- 234,257 ----
  267. X          if (needCalc) {
  268. X          needCalc = CalcRootVisible();
  269. X          }
  270. X!         if (needCalc)
  271. X!         nVis = 0;
  272. X!         else
  273. X!             nVis = MarkHiddenRoaches();
  274. X          if (nVis) {
  275. X          ev.type = SCAMPER_EVENT;
  276. X+         if (!squishWinUp && squishRoach) {
  277. X+             XMapWindow(display, squishWin);
  278. X+             squishWinUp = True;
  279. X+         }
  280. X          }
  281. X          else {
  282. X!         if (squishWinUp && squishRoach) {
  283. X!             XUnmapWindow(display, squishWin);
  284. X!             squishWinUp = False;
  285. X!         }
  286. X!         if (needCalc == 0)
  287. X!             DrawRoaches();
  288. X          eventBlock = 1;
  289. X          XNextEvent(display, &ev);
  290. X          eventBlock = 0;
  291. X***************
  292. X*** 207,218 ****
  293. X          XSync(display, False);
  294. X          break;
  295. X          
  296. X-         case Expose:
  297. X-         case MapNotify:
  298. X          case UnmapNotify:
  299. X          case ConfigureNotify:
  300. X          needCalc = 1;
  301. X          break;
  302. X          
  303. X      }
  304. X      }
  305. X--- 269,288 ----
  306. X          XSync(display, False);
  307. X          break;
  308. X          
  309. X          case UnmapNotify:
  310. X+         if (ev.xunmap.window != squishWin)
  311. X+             needCalc = 1;
  312. X+         break;
  313. X+ 
  314. X+         case MapNotify:
  315. X+         case Expose:
  316. X          case ConfigureNotify:
  317. X          needCalc = 1;
  318. X          break;
  319. X+     
  320. X+         case ButtonPress:
  321. X+         checkSquish(&ev);
  322. X+         break;
  323. X          
  324. X      }
  325. X      }
  326. X***************
  327. X*** 233,238 ****
  328. X--- 303,310 ----
  329. X      USEPRT("       -rc      roachcolor\n");
  330. X      USEPRT("       -roaches numroaches\n");
  331. X      USEPRT("       -speed   roachspeed\n");
  332. X+     USEPRT("       -squish\n");
  333. X+     USEPRT("       -rgc     roachgutscolor\n");
  334. X      
  335. X      exit(1);
  336. X  }
  337. X***************
  338. X*** 256,261 ****
  339. X--- 328,391 ----
  340. X  }
  341. X  
  342. X  /*
  343. X+    Find the root or virtual root window.
  344. X+ */
  345. X+ Window
  346. X+ FindRootWindow()
  347. X+ {
  348. X+     Window rootWin;
  349. X+     Window realRoot;
  350. X+     Atom swmVroot;
  351. X+     Window rootReturn, parentReturn, *children;
  352. X+     unsigned int numChildren;
  353. X+     int cx;
  354. X+     Atom actualType;
  355. X+     Atom actualFormat;
  356. X+     unsigned long nItems;
  357. X+     unsigned long bytesAfter;
  358. X+     Window *newRoot;
  359. X+     
  360. X+     /*
  361. X+        Get real root window.
  362. X+     */
  363. X+     realRoot = rootWin = RootWindow(display, screen);
  364. X+     
  365. X+     /*
  366. X+        Get atom for virtual root property.  If the atom doesn't
  367. X+        exist, we can assume the corresponding property does not
  368. X+        exist. 
  369. X+     */
  370. X+     swmVroot = XInternAtom(display, "__SWM_VROOT", True);
  371. X+     
  372. X+     if (swmVroot == None)
  373. X+     return rootWin;
  374. X+     
  375. X+     /*
  376. X+        Run children of root, looking for a virtual root.
  377. X+     */
  378. X+     XQueryTree(display, rootWin, &rootReturn, &parentReturn, 
  379. X+             &children, &numChildren);
  380. X+     for (cx=0; cx<numChildren; cx++) {
  381. X+     newRoot = NULL;
  382. X+     nItems = 0;
  383. X+     if (XGetWindowProperty(display, children[cx], swmVroot, 0L, 1L, False,
  384. X+         XA_WINDOW, &actualType, &actualFormat, &nItems,
  385. X+         &bytesAfter, &newRoot) == Success && actualFormat != None) {
  386. X+         if (nItems >= 1) {
  387. X+             rootWin = *newRoot;
  388. X+         }
  389. X+         if (newRoot) {
  390. X+             XFree(newRoot);
  391. X+         }
  392. X+     }
  393. X+     if (rootWin != realRoot) break;
  394. X+     }
  395. X+     XFree(children);
  396. X+     
  397. X+     return rootWin;
  398. X+ }
  399. X+ 
  400. X+ /*
  401. X     Generate random integer between 0 and maxVal-1.
  402. X  */
  403. X  int
  404. X***************
  405. X*** 404,410 ****
  406. X      for (rx=0; rx<curRoaches; rx++) {
  407. X      roach = &roaches[rx];
  408. X      
  409. X!     if (roach->intX >= 0) {
  410. X          XClearArea(display, rootWin, roach->intX, roach->intY,
  411. X          roach->rp->width, roach->rp->height, False);
  412. X      }
  413. X--- 534,540 ----
  414. X      for (rx=0; rx<curRoaches; rx++) {
  415. X      roach = &roaches[rx];
  416. X      
  417. X!     if (roach->intX >= 0 && roach->rp != NULL) {
  418. X          XClearArea(display, rootWin, roach->intX, roach->intY,
  419. X          roach->rp->width, roach->rp->height, False);
  420. X      }
  421. X***************
  422. X*** 505,515 ****
  423. X      */
  424. X      covered = XCreateRegion();
  425. X      for (wx=0; wx<nChildren; wx++) {
  426. X!     if (XEventsQueued(display, QueuedAlready)) return 1;
  427. X      errorVal = 0;
  428. X      XGetWindowAttributes(display, children[wx], &wa);
  429. X      if (errorVal) continue;
  430. X!     if (wa.map_state == IsViewable) {
  431. X          XGetGeometry(display, children[wx], &dummy, &winX, &winY,
  432. X          &winWidth, &winHeight, &borderWidth, &depth);
  433. X          if (errorVal) continue;
  434. X--- 635,648 ----
  435. X      */
  436. X      covered = XCreateRegion();
  437. X      for (wx=0; wx<nChildren; wx++) {
  438. X!     if (XEventsQueued(display, QueuedAlready)) {
  439. X!         XDestroyRegion(covered);
  440. X!         return 1;
  441. X!     }
  442. X      errorVal = 0;
  443. X      XGetWindowAttributes(display, children[wx], &wa);
  444. X      if (errorVal) continue;
  445. X!     if (wa.class == InputOutput && wa.map_state == IsViewable) {
  446. X          XGetGeometry(display, children[wx], &dummy, &winX, &winY,
  447. X          &winWidth, &winHeight, &borderWidth, &depth);
  448. X          if (errorVal) continue;
  449. X***************
  450. X*** 606,609 ****
  451. X--- 739,783 ----
  452. X      }
  453. X  
  454. X      return pix;
  455. X+ }
  456. X+ 
  457. X+ /*
  458. X+  *    squishCheck - Check to see if we have to squish any roaches.
  459. X+  */
  460. X+ checkSquish(buttonEvent)
  461. X+ XButtonEvent *buttonEvent;
  462. X+ {
  463. X+     int x, y;
  464. X+     int i;
  465. X+     int rx;
  466. X+     Roach *r;
  467. X+ /* */
  468. X+     x = buttonEvent->x;
  469. X+     y = buttonEvent->y;
  470. X+ 
  471. X+     for (rx=0; rx<curRoaches; rx++) {
  472. X+     r = &roaches[rx];
  473. X+     if (r->rp == NULL) continue;
  474. X+ 
  475. X+     if (x > r->intX &&
  476. X+         x < (r->intX + r->rp->width) &&
  477. X+         y > r->intY &&
  478. X+         y < (r->intY + r->rp->height)) {
  479. X+         XSetStipple(display, gutsGC, squishMap);
  480. X+         XSetTSOrigin(display, gutsGC, r->intX, r->intY);
  481. X+         XFillRectangle(display, rootWin, gutsGC,
  482. X+         r->intX, r->intY, squish_width, squish_height);
  483. X+ 
  484. X+         /*
  485. X+          * Delete the roach
  486. X+          */
  487. X+         for (i = rx; i < curRoaches - 1; i++)
  488. X+             roaches[i] = roaches[i + 1];
  489. X+     
  490. X+         curRoaches--;
  491. X+         rx--;
  492. X+     }
  493. X+     }
  494. X+ 
  495. X+     return;
  496. X  }
  497. X*** xroach.man    Tue Apr 02 12:26:11 1991
  498. X--- ../xroach/xroach.man    Tue Apr 02 12:46:43 1991
  499. X***************
  500. X*** 9,15 ****
  501. X  displays disgusting cockroaches on your root window. These creapy crawlies
  502. X  scamper
  503. X  around until they find a window to hide under. Whenever you move or iconify
  504. X! a window, the exposed beetles again scamper for cover.
  505. X  .SH OPTIONS
  506. X  .TP 8
  507. X  .B \-display \fIdisplay_name\fB
  508. X--- 9,15 ----
  509. X  displays disgusting cockroaches on your root window. These creapy crawlies
  510. X  scamper
  511. X  around until they find a window to hide under. Whenever you move or iconify
  512. X! a window, the exposed orthopteras again scamper for cover.
  513. X  .SH OPTIONS
  514. X  .TP 8
  515. X  .B \-display \fIdisplay_name\fB
  516. X***************
  517. X*** 26,31 ****
  518. X--- 26,38 ----
  519. X  .TP 8
  520. X  .B \-roaches \fInum_roaches\fB
  521. X  This is the number of the little critters. Default is 10.
  522. X+ .TP 8
  523. X+ .B \-squish
  524. X+ Enables roach squishing.  Point and shoot with any mouse button.
  525. X+ .TP 8
  526. X+ .B \-rgc \fIroach_gut_color\fB
  527. X+ Sets color of the guts that spill out of squished roaches.  We recommend
  528. X+ yellowgreen.
  529. X  .SH BUGS
  530. X  As given by the -roaches option. Default is 10.
  531. X  .SH COPYRIGHT
  532. ~FUNKY STUFF~
  533.  
  534. --
  535. Dan Heller
  536. ------------------------------------------------
  537. O'Reilly && Associates         Z-Code Software
  538. Senior Writer                   President
  539.